package org.come.login;

import com.tool.tcp.Sprite;
import org.come.until.CutButtonImage;

import javax.swing.*;
import java.awt.*;

/**
 * 【精灵按钮】
 *
 * @author Administrator
 *
 */
@SuppressWarnings("serial")
public class LoginBtn extends JLabel {

    // 按钮素材
    private ImageIcon[] sprite;
    // 按钮的状态
    private int zhen;
    // 出现的位置
    private int sx;
    private int sy;

    // 按钮样式类型 0正常 1表示会扩大缩小
    private int type;
    private int skx;
    private int sky;

    protected Integer V;// 左上角的小红点
    // 选择类的按钮 true表示选择
    private boolean choose;

    // 字体颜色
    protected Color[] colors;

    public LoginBtn() {
        // TODO Auto-generated constructor stub

    }

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        if (type == 2) {
            g.translate(1, 1);
            super.paintComponent(g);
            g.translate(-1, -1);
        } else {
            super.paintComponent(g);
        }
        if (V != null) {
            g.drawImage(CutButtonImage.getJT().getImage(), this.getWidth() - 10, 0, null);
        }
    }

    public LoginBtn(String path, boolean choose) {
        super();
        try {
            this.sprite = CutButtonImage.cuts(path);
            btn(1);
            btn(0);
            this.zhen = 0;
            this.choose = choose;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * 切换按钮样式
     *
     * @return 0移出和取消点击 1移入 2点击
     */
    public void btn(int type) {
        zhen = type;
        if (this.type == 0) {
            uptime(type);
        } else if (this.type == 1) {
            if (type == 1) {
                uptime(1);
            } else {
                uptime(type);
            }
        }
    }

    /**
     * 更新到指定的帧
     *
     * @return
     */
    public void uptime(int zhen) {
        if (zhen == 1) {
            this.setIcon(sprite[zhen]);
        } else if (zhen == 0) {
            this.setIcon(sprite[zhen]);
        } else {
            this.setIcon(sprite[zhen]);
        }
    }


    public int getZhen() {
        return zhen;
    }

    public void setZhen(int zhen) {
        this.zhen = zhen;
    }

    public int getSx() {
        return sx;
    }

    public void setSx(int sx) {
        this.sx = sx;
    }

    public int getSy() {
        return sy;
    }

    public void setSy(int sy) {
        this.sy = sy;
    }

    public boolean isChoose() {
        return choose;
    }

    public void setChoose(boolean choose) {
        this.choose = choose;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getSkx() {
        return skx;
    }

    public void setSkx(int skx) {
        this.skx = skx;
    }

    public int getSky() {
        return sky;
    }

    public void setSky(int sky) {
        this.sky = sky;
    }

    /** 开启小红点 */
    public void onOffRed(int v) {
        if (v == 0) {
            V = null;
        } else {
            V = v;
        }
    }

    public void draw(Graphics g) {
    }

    public Sprite getSprite() {
        return null;
    }
}
